<%@ page import="java.util.Vector" %>

<jsp:useBean id="wpb" scope="page" class="wap.rockvilletech.portal.WapPortalBean" />

<%
String tags = "root", w = "170";

boolean hasJspf = false,
        hasGraphics = false;
String[] arrBanner=null;


String 
        SeqID = "",
        AddName = "", 
        AddGraphics = "", 
        Jspf = "",
        output_String = "";

tags = request.getParameter("tags") != null ? request.getParameter("tags").toString() : tags;
w = request.getParameter("w") != null ? request.getParameter("w").toString() : w;

arrBanner = wpb.getRandomBanner(tags);

if(arrBanner!=null) {
    try {
        
        
        //SeqID, AddName, AddGraphics, Jspf, Tags
        SeqID = (arrBanner[0] != null) ? arrBanner[0] : SeqID ;
        AddName = (arrBanner[1] != null) ? arrBanner[1] :  AddName ;
        AddGraphics = (arrBanner[2] != null) ? arrBanner[2] :AddGraphics ;
        Jspf = (arrBanner[3] != null) ? arrBanner[3] : Jspf ;

        
        
        if (Jspf.length() > 1) 
        	hasJspf = true;
        if (AddGraphics.length() > 1) 
        	hasGraphics = true;
        
        if(hasGraphics) 
        	output_String = "<div class=\"css_banner\" style='background-color: #dedfe1;margin:0px'>";
        else 
        	output_String = "<div id='css_banner_text' class='css_banner_text' align=center>";

        
        if(hasJspf) output_String += "<a class='LinkIndex' href='"+ request.getContextPath() + Jspf +"'>";
        //this link is use for banner tracking call a servlet and redirect to service page
       //-- if(hasJspf) output_String += "<a href=\""+ request.getContextPath()+"/track?banId="+SeqID+"\">";
        if(hasGraphics) {
            int width = Integer.parseInt(w) - 2;
			            
            if(width < 400 && width > 200) {
                AddGraphics = AddGraphics.replace(".", "400.");
            } else if(width <= 200) {
                AddGraphics = AddGraphics.replace(".", "200.");
            }
            
            /* ISSUE: The image size was getting bigger after being processed 
            from imgsrv, so it was removed and simple image tage was used instead.
            */
            output_String += "<img src='"+ request.getContextPath() +"/imgsrv?img=adds/"+ AddGraphics +"&repo=internal&anim=1&s=0&w="+ width +"' alt='"+ AddName +"' />";
            
            //output_String += "<img src='"+ request.getContextPath() +"/images/"+ AddGraphics +"' width='"+ (width) +"' alt='"+ AddName +"' style='padding:0px; margin:0px;' />";
            //--output_String += "<img src=\""+ request.getContextPath() +"/images/adds/"+ AddGraphics +"\" alt=\""+ AddName +"\" width=\""+ (width) +"\" />";
        }
        else {
            output_String += AddName;
        }
        
        if(hasJspf) output_String += "</a>";
        
        output_String += "</div>";
        
        //log.debug("Final String: "+ output_String);
        
        out.print(output_String);
    }
    catch (Exception ex) {}
    
}
else {
    
}

%>
